#include "CoListWidget.h"

CoListWidget::CoListWidget(CoListItems* items, QWidget* parent)
: OnyxTreeView(parent, NULL)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    if (items != NULL)
    {
        setListItems(items);
    }

    Out_Log(__FUNCTION__, COCLASSNAME);
}

void CoListWidget::setListItems(CoListItems* items)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    m_listItems = items;

    m_model.clear();

    for (int i = 0; i < items->count(); i++)
    {
        QStandardItem* item = new QStandardItem((*items)[i].str);
        m_model.appendRow(item);
    }

    setModel(&m_model);
    showHeader(false);

    Out_Log(__FUNCTION__, COCLASSNAME);
}

CoListItem* CoListWidget::getListItem(int id)
{
    if (id < 0 || id >= m_listItems->count())
    {
        return NULL;
    }

    return &(*m_listItems)[id];
}
